using System;
using System.Collections.Generic;

namespace Windy.Transformations
{
    public class GeneralTransformSink<TInput, TOutput> : TransformSinkBase<TInput, TOutput, GeneralTransformSink<TInput, TOutput>>, ITransformSink<TInput, TOutput>, IDisposable
    {
        #region Initializers

        #region Constructors

        protected GeneralTransformSink()
        { }

        public GeneralTransformSink(
            Action<int, TInput> voidTransformSink = null,
            Action<int, TInput, TOutput> monoTransformSink = null,
            Action<int, TInput, IEnumerable<TOutput>> varyTransformSink = null,
            Action transformBeginHandler = null,
            Action transformCompleteHandler = null,
            Action transformAbortHandler = null)
        {
            Initialize(
                voidTransformSink,
                monoTransformSink,
                varyTransformSink,
                transformBeginHandler,
                transformCompleteHandler,
                transformAbortHandler);
        }

        #endregion

        protected virtual void Initialize(
            Action<int, TInput> voidTransformSink,
            Action<int, TInput, TOutput> monoTransformSink,
            Action<int, TInput, IEnumerable<TOutput>> varyTransformSink,
            Action transformBeginHandler,
            Action transformCompleteHandler,
            Action transformAbortHandler)
        {
            VoidTransformSink = voidTransformSink;
            MonoTransformSink = monoTransformSink;
            VaryTransformSink = varyTransformSink;

            base.Initialize(
                transformBeginHandler,
                transformCompleteHandler,
                transformCompleteHandler);
        }

        #endregion

        #region Tranform Data Sinks

        protected Action<int, TInput> VoidTransformSink;
        public override void OnVoidTransform(int index, TInput inputItem)
        {
            if (VoidTransformSink != null)
                VoidTransformSink(index, inputItem);
        }
        public GeneralTransformSink<TInput, TOutput> SetupVoidTransformSink(Action<int, TInput> sink)
        {
            VoidTransformSink = sink;
            return this;
        }

        protected Action<int, TInput, TOutput> MonoTransformSink;
        public override void OnMonoTransform(int index, TInput inputItem, TOutput outputItem)
        {
            if (MonoTransformSink != null)
                MonoTransformSink(index, inputItem, outputItem);
        }
        public GeneralTransformSink<TInput, TOutput> SetupMonoTransformSink(Action<int, TInput, TOutput> sink)
        {
            MonoTransformSink = sink;
            return this;
        }

        protected Action<int, TInput, IEnumerable<TOutput>> VaryTransformSink;
        public override void OnVaryTransform(int index, TInput inputItem, IEnumerable<TOutput> outputItems)
        {
            if (VaryTransformSink != null)
                VaryTransformSink(index, inputItem, outputItems);
        }
        public GeneralTransformSink<TInput, TOutput> SetupVaryTransformSink(Action<int, TInput, IEnumerable<TOutput>> sink)
        {
            VaryTransformSink = sink;
            return this;
        }
        #endregion
    }
}